package com.hd.tiyu.yuejian.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hd.tiyu.yuejian.Activity.OrderDetailActivity;
import com.hd.tiyu.yuejian.JavaBean.Pay;
import com.hd.tiyu.yuejian.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by love on 2017/11/8.
 */

public class PayAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List<Pay> mDataList;
    private LayoutInflater mLayoutInflater;

    public PayAdapter(Context mContext,List<Pay> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView activityname,num,paytime,bianhao,price;
        ImageView dingdanPhoto;

        public ViewHolder(View itemView) {
            super(itemView);
            activityname=itemView.findViewById(R.id.tex_huodongname);
            num=itemView.findViewById(R.id.tex_num);
            paytime=itemView.findViewById(R.id.tex_dindantime);
            bianhao=itemView.findViewById(R.id.tex_bianhao);
            price=itemView.findViewById(R.id.tex_price);

            dingdanPhoto=itemView.findViewById(R.id.img_dingdan);
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=mLayoutInflater.from(parent.getContext()).inflate(R.layout.payitem,parent,false);
        return new PayAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Pay data=mDataList.get(position);
        if (data!=null){
            ViewHolder viewHolder=(ViewHolder) holder;
            viewHolder.activityname.setText(data.getName());
            viewHolder.num.setText(data.getPrice());
            viewHolder.paytime.setText(data.getUpdate_time());
            viewHolder.bianhao.setText(data.getId());
            viewHolder.price.setText(data.getPay());
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(mContext,OrderDetailActivity.class);
                    intent.putExtra("id",data.getId());
                    intent.putExtra("paytype",data.getType());
                    mContext.startActivity(intent);
                }
            });
            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+data.getThumb()).resize(700,700).centerCrop().into(viewHolder.dingdanPhoto);
        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
}
